package Leecode;
import java.util.*;

public class Solution1 {
//    public List<String> topKFrequent(String[] words, int k) {
//        Map<String,Integer> map = new HashMap<>();
//        for(int i = 0; i < words.length; i++){
//            if(!map.containsKey(words[i])){
//                map.put(words[i],1);
//            }else{
//                int num = map.get(words[i]);
//                map.put(words[i],num+1);
//            }
//        }
//        Collection<Integer> collection = map.values();
//        System.out.println(collection);
////        List<String> list = new ArrayList<>(k);
////        while(k!=0){
////
////        }
//
//    }

    public static void main(String[] args) {
        String[] words = {"i", "love", "leetcode", "i", "love", "coding"};
        Map<String,Integer> map = new HashMap<>();
        for(int i = 0; i < words.length; i++){
            if(!map.containsKey(words[i])){
                map.put(words[i],1);
            }else{
                int num = map.get(words[i]);
                map.put(words[i],num+1);
            }
        }
        List<Map.Entry<String, Integer>> entries = new ArrayList<>(map.entrySet());
        Collections.sort(entries, Map.Entry.comparingByValue(Collections.reverseOrder()));

        List<String> list = new ArrayList<>();
        for (int i = 0; i < 3 && i < entries.size(); i++) {
            list.add(entries.get(i).getKey());
        }
        System.out.println(list);

    }
public static void main1(String[] args) {
    Map<String,Integer> map = new HashMap<>();
    map.put("apple",1);
    map.put("banana",1);
    map.put("apple",2);
    System.out.println(map);
    Set<Integer> set = new HashSet<>();
    set.add(1);
    Object[] arr = set.toArray();
    System.out.println(arr);
    System.out.println(arr[0]);
}
}
